var express = require('express');
var db = require('./db.js')

var router = express.Router()
var bodyParser = require('body-parser');
var md5 = require('md5-nodejs');
var urlencodedParser = bodyParser.urlencoded({ extended: false })
var multer = require('multer');

router.get('/list', async function (req, res) {
    let { date, uid } = req.query

    let data;
    if (uid != 0 && uid != undefined) {
        var sql = `select s.date, s.score, s.total_time, s.paper, u.name as name from score as s, users as u where u.id = s.uid and s.date like '${date}%' and uid = ${uid}`
    } else {
        var sql = `select s.date, s.score, s.total_time, s.paper, u.name as name from score as s, users as u where u.id = s.uid and s.date like '${date}%'`

    }
    data = await db.doSql(sql)
    res.send(JSON.stringify(db.hand(data)))
})

module.exports = router